package com.zyw.util;

import java.util.Map;
import java.util.StringTokenizer;

public class WordCount {
	 
    public void sort(int[] arry) {
        int temp;
        for (int i = 0; i < arry.length; i++) {
            for (int j = i; j < arry.length; j++) {
                if (arry[i] > arry[j]) {
                    temp = arry[i];
                    arry[i] = arry[j];
                    arry[j] = temp;
                }
            }
 
        }
        for (int k = 0; k < arry.length; k++) {
            System.out.print(arry[k] + " ");
        }
    }
    public static Map<String, Integer> count(String text, Map<String, Integer> resultMap){
    	 Map<String, Integer> hashMap = resultMap;
    	 // 用正则表达式来过滤字符串中的所有标点符号
         String regex = "[【】、.。,，。\"!--;:?\'\\]\r\n]";
         for(String value:text.split("\r\n")){
        	 value = value.replaceAll(regex, " ");
        	 // 使用StringTokenizer来分词(StringTokenizer详见JDK文档)
             StringTokenizer tokenizer = new StringTokenizer(value);
             while (tokenizer.hasMoreTokens()) {
                 String word = tokenizer.nextToken();
                 if (!hashMap.containsKey(word)) {
                     hashMap.put(word, new Integer(1));
                 } else {
                     int k = hashMap.get(word).intValue() + 1;
                     hashMap.put(word, new Integer(k));
                 }
             }
         }
    	return hashMap;
    }
	
}